package net.sunofbeaches.controller.admin;

import net.sunofbeaches.pojo.FriendLink;
import net.sunofbeaches.response.ResponseResult;
import net.sunofbeaches.services.FriendLinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.nio.channels.FileLock;

@RestController
@RequestMapping("admin/friend_link")
public class FriendsAdminApi {
    @Autowired
    private FriendLinkService friendLinkService;

    @PreAuthorize("@permission.adminPermission()")
    @PutMapping
    public ResponseResult addFriedLink(@RequestBody FriendLink friendLink) {
        return friendLinkService.addFriendLink(friendLink);
    }

    /**
     * 真实删除（非禁用）
     *
     * @param friendLinkId
     * @return
     */
    @PreAuthorize("@permission.adminPermission()")
    @DeleteMapping("/{friendLinkId}")
    public ResponseResult deleteFriedLink(@PathVariable("friendLinkId") String friendLinkId) {
        return friendLinkService.deleteFriendLink(friendLinkId);
    }

    @PreAuthorize("@permission.adminPermission()")
    @PutMapping("{friendLinkId}")
    public ResponseResult updateFriendLink(@PathVariable("friendLinkId") String friendLinkId,
                                           @RequestBody FriendLink friendLink) {
        return friendLinkService.updateFriendLink(friendLinkId,friendLink);
    }
    @PreAuthorize("@permission.adminPermission()")
    @GetMapping("/list")
    public ResponseResult listFriendLinks(){
        return friendLinkService.listFriendLinks();
    }

    @PreAuthorize(("@permission.adminPermission()"))
    @GetMapping("{friendLinkId}")
    public ResponseResult getFriendLink(@PathVariable ("friendLinkId")String friendLinkId){
        return friendLinkService.getFriendLink(friendLinkId);
    }

}
